package com.wgts.wgts.mvp.view.activity.shopkeeper;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.netmodle.resp.RecordSpreadEntity;
import com.wgts.wgts.tools.AppInfor;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

public class RvAdapterRecordSpreadAdapter extends RecyclerView.Adapter<RvAdapterRecordSpreadAdapter.PrizeInfoViewHolder> {


    private Context mContext;
    private List<RecordSpreadEntity> entity;

    public RvAdapterRecordSpreadAdapter(Context context, List<RecordSpreadEntity> entity) {
        this.entity = entity;
        this.mContext = context;
    }


    public void updateList() {

        if (!entity.isEmpty()) {

            entity.add(entity.get(0));
            entity.remove(0);
            notifyItemRangeRemoved(0, 1);
        }
    }

    @Override
    public PrizeInfoViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {

        View view = LayoutInflater.from(viewGroup.getContext())
                .inflate(R.layout.shop_keep_text_banner, viewGroup, false);
        return new PrizeInfoViewHolder(view);
    }


    @Override
    public void onBindViewHolder(PrizeInfoViewHolder holder, int i) {

        StringBuilder nickName = new StringBuilder(entity.get(i).userNickName);

        if (nickName.length() > 2) {
            nickName.replace(1, nickName.length() - 1, "*");
        }

        StringBuilder relationNickName = new StringBuilder(entity.get(i).relationUserNickName);
        if (relationNickName.length() > 2) {
            relationNickName.replace(1, relationNickName.length() - 1, "*");
        }

        //MoHuGlide.getInstance().glideImgsFormList(holder.imgHead, entity.get(i).userImage, mContext);
        holder.tvUserName.setText(nickName.toString());

        if(AppInfor.getInstance().getUserState() < 2){
            holder.tvTitle.setText("邀请" + relationNickName + "成为金牌推手");
        }else{
            holder.tvTitle.setText("邀请" + relationNickName + "成为钻石推手");
        }
        
        holder.tvMoney.setText("奖励" + entity.get(i).scoreRecordMoney + "元");

    }

    @Override
    public int getItemCount() {
        if(entity.size() > 10){
            return 10;
        }else{
            return entity.size();
        }
    }

    class PrizeInfoViewHolder extends RecyclerView.ViewHolder {



        @BindView(R.id.img_head)
        CircleImageView imgHead;
        @BindView(R.id.tv_user_name)
        TextView tvUserName;
        @BindView(R.id.tv_money)
        TextView tvMoney;
        @BindView(R.id.tv_title)
        TextView tvTitle;

        PrizeInfoViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
